package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.RoomInfo;
import com.xuetang9.t9.hotel.beans.RoomType;
import com.xuetang9.t9.hotel.mapper.condition.impl.RoomInfoCondition;
import com.xuetang9.t9.hotel.services.IRoomTypeService;
import com.xuetang9.t9.hotel.utils.HttpCodeEnum;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 房间类型
 * @author pang
 */
@Controller
@RequestMapping("/roomtype")
@ResponseBody
public class RoomTypeController {
    @Autowired
    private IRoomTypeService roomTypeService;

    /**
     * 总览房间
     * @param
     * @return
     */
    @RequestMapping(value = "/show")
    private PageBean show(){
        return roomTypeService.findByAll();
    }

    /**
     * 总览房间
     * @param
     * @return
     */
        @RequestMapping(value = "/showtype")
    private PageBean showType(){
        return roomTypeService.findByTypeAll();
    }



    /**
     * 房间保存
     * @param
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    private ResponseResult save(@RequestBody RoomType roomType){
        if(roomType == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(roomTypeService.save(roomType)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

    /**
     * 房间修改
     * @param
     * @return
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    private ResponseResult update(@RequestBody RoomType roomType){
        if(roomType == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(roomTypeService.alter(roomType)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

    /**
     * 房间删除
     * @param
     * @return
     */
    @RequestMapping(value = "/remove/{id}")
    private ResponseResult save(@PathVariable("id") Integer id){
        if(id == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(roomTypeService.remove(id)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }
}
